<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="app">
    {{message}}
    <component-a></component-a>
</div>
<script>
    var bus = new Vue()
    Vue.component('component-a',{
        template:`<button @click="handleEvent">传递事件</button>`,
        methods:{
            handleEvent(){
                bus.$emit('on-message','来自组件component-a的内容')
            }
        }
    })
    var vm = new Vue({
        el:'#app',
        data:{
            message: ''
        },
        mounted(){
            bus.$on('on-message',msg => {
                this.message=msg
            })
        },
        methods:{}
    })
</script>
</body>
</html>
